package com.timemanage.activity.ui.home

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.timemanage.R
import com.timemanage.activity.SortDetail
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList

class sortAdapter(val context: Context,val sort_id:ArrayList<String>,val sort_name:ArrayList<String>,
                  val sort_body:ArrayList<String>,): RecyclerView.Adapter<sortAdapter.MyViewHolder>() {
    inner class MyViewHolder(view: View):RecyclerView.ViewHolder(view){
        val sortName:TextView = itemView.findViewById(R.id.sort_name_text)
        val sortBody:TextView = itemView.findViewById(R.id.sort_body_text)
        val mainLayout: LinearLayout = itemView.findViewById(R.id.mainLayout)
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(
            R.layout.row_item1,parent,false
        )
        return MyViewHolder(view)
    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        holder.sortName.text = sort_name[position]
        holder.sortBody.text = sort_body[position]
        holder.mainLayout.setOnClickListener {
            val intent = Intent(context,SortDetail::class.java)
            intent.putExtra("ID",sort_id[position])
            intent.putExtra("title",sort_name[position])
            context.startActivity(intent)
        }
    }
    //val sdf = SimpleDateFormat("dd/MM/yy hh:mm a")
    //val netDate = Date(item.timestamp)
    //val date =sdf.format(netDate)
    override fun getItemCount() = sort_name.size

}
